from helpers.director.engine import BaseEngine,page
from helpers.director.base_data import inspect_dict
from helpers.director.shortcut import page_dc
from helpers.director.engine import BaseEngine, page, fa, can_list, can_touch
from django.contrib.auth.models import User, Group
from helpers.func.collection.container import evalue_container

from django.utils.translation import ugettext as _
from django.conf import settings
from helpers.director.access.permit import has_permit
from helpers.mobile.base_data import mb_page_dc

from quality.models import ProdRecord,FailSource,FailKind,ProcessingScheme,ProdModel,DepartMent,Userinfo,QualityEvent,FailAbstract
from django.contrib.auth.models import User, Group

# from helpers.case.act_log.models import SystemMessage
# from helpers.case.act_log.models import BackendOperation

class PcMenu(BaseEngine):
    url_name = 'quality'
    title = '质量管理' #''
    brand = '质量' #''
    mini_brand = 'Q'
    menu_search=False
    need_staff=True
    access_from_internet=False
    #ui_theme='skin-green-light'
    #logout_url = '/pc/logout?next=/pc'
    
    @property
    def menu(self):
        crt_user = self.request.user
        menu = [
            {'label': '待办事件', 'url':  page('todo_event'), 'icon': fa('fa-home'), 'visible': True},
            
            #{'label': '首页', 'url':  page('enginhome'), 'icon': fa('fa-home'), 'visible': True},
            {'label': '质量事件', 'url':  page('quality'), 'icon': fa('fa-balance-scale'), 'visible': can_touch(QualityEvent,crt_user)},
            {'label': '生产批次', 'url':  page('prodrecord'), 'icon': fa('fa-truck'), 'visible': can_touch(ProdRecord,crt_user)},
            {'label': '基础数据', 'icon': fa('fa-delicious'), 
             'submenu':[
                 #{'label':'产品部件','url':page('product-part')},
                 {'label':'不合格来源','url':  page('failsource'),'visible':can_touch(FailSource,crt_user) } ,
                 {'label':'不良分类','url':  page('failkind'), 'visible':can_touch(FailKind,crt_user)} ,
                 {'label':'解决方案','url':page('processing-scheme'),'visible':can_touch(ProcessingScheme,crt_user)},
                 {'label':'商品信息','url':page('prodmodel'),'visible':can_touch(ProdModel,crt_user)},
                 {'label':'不良简述','url':page('FailAbstract'),'visible':can_touch(FailAbstract,crt_user)},
                 
                 ]},

            #{'label': '学生班级', 'icon': fa('fa-home'), 'visible': True,
             #'submenu':[
                 #{'label':'班级管理','url':page('studentclass')},
                 #{'label':'学生管理','url':  page('student'), },
                 #]},
             #{'label': '成绩管理', 'icon': fa('fa-home'), 'visible': True,
             #'submenu':[
                 #{'label':'成绩管理','url':page('score')},
          
                 #]},
            {'label': '数据分析', 'icon': fa('fa-delicious'), 
                  'submenu':[
                      #{'label':'产品部件','url':page('product-part')},
                      {'label':'图表数据','url':  page('statis_home'),'visible':has_permit(crt_user,'ansys_data') } ,
                      
                      {'label':'质量事件分析','url':  page('statis_event'),'visible':has_permit(crt_user,'quality_event_ansys') } ,
                    
                 ]},
                 
            
            {'label': '人员及组织', 'icon': fa('fa-gear'), 
             'submenu': [
                {'label':'部门管理','url':page('department'),'visible':can_touch(DepartMent,crt_user)},
                {'label':'人员管理','url':page('userinfo'),'visible':can_touch(Userinfo,crt_user)},
                {'label': '权限分组', 'url': page('jb_group'),'visible': can_touch(Group, crt_user)},
             ]},
              #{'label': '编辑器', 'url':  page('blockeditor'), 'icon': fa('fa-home'), 'visible': True},
            
            
            #{'label': '系统管理', 'icon': fa('fa-gear'), 'visible': True,
             #'submenu': [
                 ##{'label':'系统设置','url':page('sys_settings'),'visible':has_permit(crt_user,'system-setting')},
                 #{'label': '账号管理', 'url': page('jb_user'),},
                 #{'label': '权限分组', 'url': page('jb_group'),},
                 ##{'label':'操作日志','url':page('backendoperation_log'),'visible':can_touch(BackendOperation, crt_user)}
                 
             #]},
            
        ]


        return menu
    
    def custome_ctx(self, ctx):
        if 'extra_js' not in ctx:
            ctx['extra_js'] = []
        ctx['extra_js'].append('quality_ctrl')
        ctx['menu_expand_all']=True
        return ctx
    
PcMenu.add_pages(page_dc)




